package com.junbao.androidinterview.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;

import androidx.annotation.StringRes;

import com.junbao.androidinterview.R;

/**
 * author : Majunbao
 * github : https://github.com/MaJunBaox
 * time   : 2022/8/7 4:29 下午
 * desc   :
 */
public class LoadingDialog extends AlertDialog {

    private Build build;

    public LoadingDialog(Build build , int theme) {
        super(build.context , theme);
        this.build = build;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.dialog_loading);
        setCanceledOnTouchOutside(false);
        setCancelable(false);
    }

    public static class Build{

        Context context;
        String loadingText;

        public Build(Context context){
            this.context = context;
        }
        /**
         * text 文案
         *
         * @param text
         * @return
         */
        public Build loadingText(String text) {
            this.loadingText = text;
            return this;
        }

        /**
         * text 文案
         *
         * @param textRes
         * @return
         */
        public Build loadingText(@StringRes int textRes) {
            return loadingText(context.getString(textRes));
        }

        public LoadingDialog build() {
            LoadingDialog dialog = new LoadingDialog(this, R.style.LoadingDialog);
            return dialog;
        }

    }
}
